
angular.module('scanPrint', [
    'ionic',
    'ngCordova',
    
    'scanPrint.controllers', 
    'scanPrint.services'
])

    .run(['$ionicPlatform', '$timeout', 'InitService',
        function ($ionicPlatform, $timeout, InitService) {
            $ionicPlatform.ready(function () {
                // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
                // for form inputs)
                if (window.cordova && window.cordova.plugins.Keyboard) {
                    cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
                }
                if (window.StatusBar) {
                    StatusBar.styleDefault();
                }
                InitService.finally(function () {
                    if (navigator.splashscreen) {
                        $timeout(function () {
                            navigator.splashscreen.hide();
                            // if (window.StatusBar) {
                            //     StatusBar.show();
                            // }
                        }, 500);
                    }
                });
            });
            ionic.Platform.isFullScreen = true;
        }
    ])

    .config(['$stateProvider', '$urlRouterProvider', '$ionicConfigProvider',
        function ($stateProvider, $urlRouterProvider, $ionicConfigProvider) {
            
            // $httpProvider.interceptors.push('HttpInterceptor');

            $stateProvider
                .state('home', {
                    url: '/home',
                    templateUrl: 'tpls/home.html',
                    controller: 'HomeCtrl',
                    resolve: {
                        //初始化服务走完，运行首页
                        'loading': ['InitService', function (InitService) {
                            return InitService;
                        }]
                    }
                });
            $urlRouterProvider.otherwise('/home');
            
            $ionicConfigProvider.platform.android.scrolling.jsScrolling(true);
            $ionicConfigProvider.platform.android.navBar.alignTitle('center');
            $ionicConfigProvider.platform.android.backButton.previousTitleText(false);
            $ionicConfigProvider.platform.android.backButton.icon('ion-ios-arrow-back');
            $ionicConfigProvider.platform.android.spinner.icon('ios');
            $ionicConfigProvider.platform.android.views.swipeBackEnabled(true);
            $ionicConfigProvider.platform.android.views.swipeBackHitWidth(45);
            $ionicConfigProvider.platform.android.tabs.style('standard');
            $ionicConfigProvider.platform.android.tabs.position('bottom');
            $ionicConfigProvider.platform.android.form.toggle('large');

            $ionicConfigProvider.platform.default.backButton.previousTitleText(false);
            $ionicConfigProvider.platform.default.backButton.text(false);
        }
    ]);

(function () {
    if (typeof cordova === 'undefined') {
        angular.element(document).ready(onReady);
    } else {
        document.addEventListener("deviceready", onReady, false);
    }

    function onReady () {
        angular.bootstrap(document, ['scanPrint']);
    }
})();